// @algorithm @lc id=1956 lang=cpp 
// @title maximum-element-after-decreasing-and-rearranging


// #define print(...)
// @test([2,2,1,2,1])=2
// @test([100,1,1000])=3
// @test([1,2,3,4,5])=5
class Solution {
public:
    int maximumElementAfterDecrementingAndRearranging(vector<int>& arr) {
        sort(arr.begin(), arr.end());
        arr[0] = 1;
        for(int i=1; i<arr.size(); i++)
            arr[i] = min(arr[i], arr[i-1]+1);
        return *arr.rbegin();
    }
};